import 'dart:convert';

import 'package:auto_orientation/auto_orientation.dart';
import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/data/store/auth_store.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:qrscan/qrscan.dart' as scanner;
import 'state.dart';

class UserIndexController extends GetxController {
  final UserIndexState state = UserIndexState();

  @override
  void onInit() {
    super.onInit();
  }

  toUserInformation() {
    if (AuthStore.to.isLogin) {
      Get.toNamed(RouterName.userInformation);
    } else {
      Get.toNamed(RouterName.userLogin);
    }
  }

  void toSystemSetting() {
    Get.toNamed(RouterName.userSystemSettingIndex);
  }

  void scan() async {
    String? cameraScanResult = await scanner.scan();
    print(cameraScanResult);

    try {
      var data = json.decode(cameraScanResult!);

      switch (data['type']) {
        // 登录web端
        case '3':
          Get.toNamed(RouterName.commonScanLoginWeb,arguments: data['data']);
          break;
      }
    } catch (e) {}
  }
}
